package com.thinkgem.jeesite.modules.sys.web;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.product.service.product.GenProductService;
import com.thinkgem.jeesite.modules.shop.service.order.ShopOrderService;

/**
 * 用户Controller
 * 
 * @author ws
 * @version 2016-12-20
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/index")
public class SysIndexController extends BaseController {

    @Autowired
    private ShopOrderService shopOrderService;

    @Autowired
    private GenProductService genProductService;

    @RequestMapping(value = { "home" })
    public String index(Model model) {
        model.addAttribute("orderNumber", shopOrderService.sumOrder());
        model.addAttribute("outOfStockNumber", genProductService.sumOutOfStock());
        return "modules/sys/sysHome";
    }
    
    @RequestMapping(value = { "messageCount" })
    @ResponseBody
    public Long messageCount(Model model) {
    	Long messageCount=shopOrderService.messageOrderCount()+genProductService.sumOutOfStock();
    	if(messageCount==null){
    		messageCount=0L;
    	}
        return messageCount;
    }
    
    @RequestMapping(value = { "message" })
    @ResponseBody
    public Map<String, Long> message(Model model) {
    	Map<String, Long> sumMessageMap =shopOrderService.sumMessageOrder();
    	sumMessageMap.put("outOfStockNumber", genProductService.sumOutOfStock());
        return sumMessageMap;
    }
}
